package com.sq.partner.manager.service.impl;

import java.text.DecimalFormat;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.sq.partner.manager.dao.INlifeRiskDao;
import com.sq.partner.manager.mybatis.model.NlifeRisk;
import com.sq.partner.manager.service.NlifeRiskService;
import com.sq.partner.manager.util.LogUtil;

/**
 * 条款责任信息Service实现类
 * @author zhouxiuxiu
 *
 */
@Service
public class NlifeRiskServiceImpl implements NlifeRiskService {
    private static Logger logger = LogUtil
            .getLog(NlifeRiskServiceImpl.class);
    
    @Resource
    INlifeRiskDao nlifeRiskDao;
    
    /**
     * 根据投保方案，查询险种保额
     * @param nlifePlanNO
     * @return
     * @throws Exception
     */
    @Override
    public List<Map<String,Object>> queryNlifeRiskAmt(String nlifePlanNo)
            throws Exception {
        List<Map<String, Object>> lists = nlifeRiskDao.queryNlifeRiskAmt(
                nlifePlanNo);
        if(lists == null || lists.size() == 0){
            logger.error("没有险种信息");;
            throw new Exception("没有险种信息");
        }
        // 保额保留 2 位小数展示
        for (int i = 0; i < lists.size(); i++) {
            lists.get(i).put("COV_AMT", format(lists.get(i).get("COV_AMT")));
        }
        return lists;
    }
    
    /**
     * 数字转换
     * @param obj
     * @return
     */
    private static String format(Object obj) {
        String floatDown = "0.00";
        DecimalFormat df = new DecimalFormat( "0.00" );
        if(obj!=null){
            floatDown =df.format(Double.parseDouble(obj.toString()));
        }
        return floatDown;
    }

	@Override
	public List<NlifeRisk> queryNlifeRiskByParam(Map<String, Object> map)
			throws Exception {
		
		return nlifeRiskDao.queryNlifeRiskByParam(map);
	}

}
